<?php
namespace app\ice\model;
use think\Db;
use think\Model;

class Reputation extends Model
{
    protected $table = 'ig_reputation';
    protected $pk = 'id';
    protected $autoWriteTimestamp = 'create_time';
    public function addParkOrder($param){
        $result = $this->allowField(true)->save($param);
        return $result;
    }

    // 查看订单详情
    public function getParkOrderDetail($param)
    {
        $data = $this->where('id',$param['orderId'])->where('uid',$param['uid'])->find();
        return $data;
    }

    public function getOrderGoods($oid){
        $goods = $this->alias('a')
            ->field('a.goods_id,pic,b.goods_name,b.goods_price,b.goods_num')
            ->join('ig_order_goods b','a.order_id = b.order_id')
            ->join('ig_goods c','c.id = b.goods_id')
            ->where('b.order_id',$oid)->select();
            foreach ($goods as $key => $value) {
                $value['pic'] = config('host').$value['pic'];
            }
        return $goods;
    }

    public function getParkOrderList($param)
    {
        $data = $this->alias('a')->where('uid',$param['uid'])->join('cbdd_park b','a.park_id = b.id')->select();
        foreach ($data as $key => &$v) {
            $v['show_time'] = date('Y-m-d H:i:s',($v['order_time'] + $v['day'] *60*60*24));
            $v['order_time'] = date('Y-m-d H:i:s',$v['order_time']);
        }
        unset($key);
        unset($v);
        return $data;
    }
}